import unittest
import requests
import logging
import utils
from api.login import LoginApi
from parameterized import parameterized


class TestInfoVerifyCode(unittest.TestCase):

    @classmethod
    def setUp(cls) -> None:
        cls.session = requests.session()
        cls.login_api = LoginApi(cls.session)

    def tearDown(self) -> None:
        self.session.close()

    # 获取短信验证码
    @parameterized.expand(
        utils.read_file_freedom("sms_code", "phone,imgVerifyCode,status_code,status,description"))
    def test01_info_verify_code(self, phone, imgVerifyCode, status_code, status, description):
        # 测试数据
        # phone = "13203003591"
        # img_verify_code = "8888"

        # 调用接口
        res_img = self.login_api.get_img_verify_code(1)
        response = self.login_api.get_info_verify_code(phone, imgVerifyCode)

        # 断言
        self.assertEqual(status_code, res_img.status_code)
        # self.assertEqual(200,response.status_code)
        # self.assertEqual(200,response.json().get("status"))
        # self.assertIn("短信发送成功",response.json().get("description"))
        utils.common_assert(self, response, status_code, status, description)

        # 输出日志
        logging.info(f"获取短信验证码的结果为：{response.text}")

    # 获取短信验证码失败（图片验证码错误）
    # def test02_info_verify_code(self):
    #     # 测试数据
    #     phone = "13203003591"
    #     img_verify_code = "8881"
    #
    #     # 调用接口
    #     res_img = self.login_api.get_img_verify_code(1)
    #     response = self.login_api.get_info_verify_code(phone, img_verify_code)
    #
    #     # 断言
    #     self.assertEqual(200, res_img.status_code)
    #     # self.assertEqual(200, response.status_code)
    #     # self.assertEqual(100, response.json().get("status"))
    #     # self.assertIn("图片验证码错误", response.json().get("description"))
    #     utils.common_assert(self, response, 200, 100, "图片验证码错误")
    #
    #     # 输出日志
    #     logging.info(f"获取短信验证码的结果为：{response.text}")
    #
    # # 获取短信验证码失败（图片验证码为空）
    # def test03_info_verify_code(self):
    #     # 测试数据
    #     phone = "13203003591"
    #     img_verify_code = ""
    #
    #     # 调用接口
    #     res_img = self.login_api.get_img_verify_code(1)
    #     response = self.login_api.get_info_verify_code(phone, img_verify_code)
    #
    #     # 断言
    #     self.assertEqual(200, res_img.status_code)
    #     # self.assertEqual(200, response.status_code)
    #     # self.assertEqual(100, response.json().get("status"))
    #     # self.assertIn("图片验证码错误", response.json().get("description"))
    #     utils.common_assert(self, response, 200, 100, "图片验证码错误")
    #
    #     # 输出日志
    #     logging.info(f"获取短信验证码的结果为：{response.text}")
